/*
 * @Author: Troubadour 2276791354@qq.com
 * @Date: 2024-03-08 11:57:14
 * @LastEditors: Troubadour 2276791354@qq.com
 * @LastEditTime: 2024-03-08 20:40:20
 * @Version:
 * @Description:
 */

#ifndef __ULTRASONIC_H__
#define __ULTRASONIC_H__

#include "main.h"


#define ULTRASONIC_FILTER_ENABLE    (1)
#define ULTRASONIC_FILTER_NUMBER    (5)
#define ULTRASONIC_QUANTITY         (1)

typedef enum
{
    UTS_RESULT_OK = 0,
    UTS_TRIGGER,
    UTS_ECHO,
    UTS_UPDATA,
    UTS_RESULT_ERROR = 99,
}UltrasonicState;

typedef struct
{
#if ULTRASONIC_FILTER_ENABLE
    uint8_t FilterCnt;
    uint16_t TransmitTimeFilter_us[ULTRASONIC_FILTER_NUMBER];
#endif
    uint16_t TransmitTime_us;
    uint16_t EchoHighTime_us;
    uint16_t EchoLowTime_us;
    UltrasonicState State;
    UltrasonicState Updata;
    double Distance_m;
    double Distance_cm;
    GPIO_TypeDef *Trig_GPIOx;
    uint16_t Trig_GPIO_Pin;
    GPIO_TypeDef *Echo_GPIOx;
    uint16_t Echo_GPIO_Pin;
}Ultrasonic_Type;

extern Ultrasonic_Type UltrasonicData[ULTRASONIC_QUANTITY];
extern uint8_t UltrasonicQuantity;

UltrasonicState Ultrasonic_GetUpdataState(uint8_t num);
double Ultrasonic_GetDisCm(uint8_t num);
double Ultrasonic_GetUpdataDisCm(uint8_t num);
void Ultrasonic_Init(void);
void Ultrasonic_Task(void);


#endif  /* __ULTRASONIC_H__ */
